package com;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class TestSplitMap {
	
	public static void main(String[] args) {
		Map<String, List<String>> map = new HashMap<>();
		List<String> one = new ArrayList<>();
		for(int i=0;i<200;i++) {
			one.add(i+"");
		}
		map.put("A", one);
		
		List<String> two = new ArrayList<>();
		for(int i=0;i<200;i++) {
			two.add(i+"_"+i);
		}
		map.put("B", two);
		
		List<String> three = new ArrayList<>();
		for(int i=0;i<99;i++) {
			three.add("C_"+i);
		}
		map.put("C", three);
		System.out.println(map.size());
		map = splitMap(map);
		System.out.println(map.size());
	}

	private static Map<String, List<String>> splitMap(Map<String, List<String>> map) {
		Map<String, List<String>> result = new HashMap<>();
		int bootLength = 99;
		for(String key : map.keySet()) {
			List<String> list = map.get(key);
			if(list.size() <=bootLength) {
				result.put(key, list);
			}else {
				int startIndex = 0;
				int loopBoot = (int) Math.ceil(list.size() * 1.0 / bootLength);
				for(int i = 0; i < loopBoot; i++) {
					List<String> newList;
					if(startIndex + bootLength > list.size()) {
						newList = list.subList(startIndex, list.size());
					}else {
						newList = list.subList(startIndex, startIndex + bootLength);
					}
					startIndex = startIndex + bootLength;
					result.put(key.concat("++"+i), newList);
				}
			}
		}
		map.clear();
		return result;
	}

}
